package com.tpolteam.tpol.tpol2019.demo.ui

import android.content.Intent
import android.os.Bundle
import androidx.core.view.GravityCompat
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.navigation.NavigationView
import com.google.android.material.snackbar.Snackbar
import com.tpolteam.tpol.R
import com.tpolteam.tpol.tpol2019.ScrollingActivity
import com.tpolteam.tpol.tpol2019.demo.glide.GlideDemosActivity
import com.tpolteam.tpol.tpol2019.demo.okhttp3.OkhttpTestActivity
import com.tpolteam.tpol.tpol2019.demo.ui.constraintlayout.TestConstraintLayoutActivity
import kotlinx.android.synthetic.main.activity_demo_drow.*
import kotlinx.android.synthetic.main.app_bar_demo_drow.*

class DemoDrowActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_demo_drow)
        setSupportActionBar(toolbar)

        fab.setOnClickListener { view ->
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show()
        }

        val toggle = ActionBarDrawerToggle(
                this, drawer_layout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close)
        drawer_layout.addDrawerListener(toggle)
        toggle.syncState()

        nav_view.setNavigationItemSelectedListener(this)

        val process = Runtime.getRuntime().availableProcessors()
        val maxMemory = Runtime.getRuntime().maxMemory() / 1024

        phoneInfos.text = "process:${process} || maxMemory:${maxMemory}"

    }

    override fun onBackPressed() {
        if (drawer_layout.isDrawerOpen(GravityCompat.START)) {
            drawer_layout.closeDrawer(GravityCompat.START)
        } else {
            super.onBackPressed()
        }
    }

    override fun onCreateOptionsMenu(menu: Menu): Boolean {
        // Inflate the menu; this adds items to the action bar if it is present.
        menuInflater.inflate(R.menu.demo_drow, menu)
        return true
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        when (item.itemId) {
            R.id.action_settings -> return true
            else -> return super.onOptionsItemSelected(item)
        }
    }

    override fun onNavigationItemSelected(item: MenuItem): Boolean {
        // Handle navigation view item clicks here.
        when (item.itemId) {
            R.id.nav_camera -> {
                // Handle the camera action
            }
            R.id.nav_gallery -> {
                startActivity(Intent(baseContext, OkhttpTestActivity::class.java))
            }
            R.id.nav_slideshow -> {
                startActivity(Intent(baseContext, GlideDemosActivity::class.java))
            }
            R.id.nav_manage -> {
                startActivity(Intent(baseContext, DemoTabsActivity::class.java))
            }
            R.id.nav_share -> {
                startActivity(Intent(baseContext, ScrollingActivity::class.java))
            }
            R.id.nav_send -> {
                startActivity(Intent(baseContext, TestConstraintLayoutActivity::class.java))
            }
        }

        drawer_layout.closeDrawer(GravityCompat.START)
        return true
    }
}
